package Servlet;

import DAO.AdminDAO;
import DAO.DAOFactory;
import DAO.StaffDAO;
import javabean.Admin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/ApprovalStaff")
public class ApprovalStaffServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8"); // 设置编码
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");
        req.getParameter("pendingID");
        Admin loginAdmin = (Admin) req.getSession().getAttribute("loginAdmin");
        AdminDAO adminDAO = (AdminDAO) DAOFactory.getAdminDAOInstance();
        boolean isSuccess = adminDAO.pendingStaff(Integer.parseInt(req.getParameter("pendingID")),loginAdmin.getAdminID());
        if(isSuccess){
            PrintWriter out = resp.getWriter();
            out.print("<script>alert('审批成功！');window.location.href='pendingStaff'</script>");
        }else{
            PrintWriter out = resp.getWriter();
            out.print("<script>alert('审批失败！');window.location.href='pendingStaff'</script>");
        }
    }
}
